home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / misc~1 / 199 / lib / gem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-14  |  19.1 KB  |  1,092 lines

  1. /* 
  2.  * the GEM library
  3.  * contains both AES and VDI stuff, though not all of it
  4.  */
  5.  
  6. #include "gem.h"
  7.  
  8. extern short    ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7;
  9. extern short    ii0, ii1, ii2, ii3, ii4, ii5, ii6, ii7, ii8, ii9,
  10.         ii10, ii11, ii12, ii13, ii14, ii15;
  11. extern short    io0, io1, io2, io3, io4, io5, io6, iox[40];
  12. extern short    pi0, pi1, pi2, pi3, pi4, pi5, pi6, pi7, pix[6];
  13. extern short    po0, po1, po2, po3, pox[12];
  14. extern short    *ai0, *ai1;
  15. extern short    *ao0;
  16. extern    short    *vdi0, *vdi1, *vdi2, *vdi3, *vdi4, *vdi5;
  17. extern short    *aes0, *aes1, *aes2, *aes3, *aes4, *aes5;
  18. extern short    global[16];
  19.  
  20. /* 
  21.  * the c runtime start up routine for GEM processes
  22.  * no argv argc stuff, no stdio (use TOS routines for file access)
  23.  *
  24.  * assumes a startup prg.s of
  25.  *    . _bstk 2048
  26.  *    . _estk 4
  27.  *    taa 7 6
  28.  *    lll 4 0
  29.  *    sgl _estk
  30.  *    lag _estk 7
  31.  *    jsr _cprg
  32.  * plus definitions for all the above externs
  33.  */
  34.  
  35. #define SETBLK    0x4A
  36. #define TERM    0x4C
  37.  
  38. _cprg(tpa) long tpa; {
  39.     int i;
  40.     long x, *lp;
  41.  
  42.     /* compute size of program, give memory back to TOS */
  43.     lp = tpa;
  44.     x = lp[3] + lp[5] + lp[7] + 0x100;
  45.     if (trap(1, SETBLK, 0, tpa, x))
  46.         appl_exit(-1);
  47.  
  48.     /* set up the aespb and vdipb arrays */
  49.     aes0 = &ct0;
  50.     aes1 = global;
  51.     aes2 = &ii0;
  52.     aes3 = &io0;
  53.     aes4 = &ai0;
  54.     aes5 = &ao0;
  55.     vdi0 = &ct0;
  56.     vdi1 = &ii0;
  57.     vdi2 = &pi0;
  58.     vdi3 = &io0;
  59.     vdi4 = &po0;
  60.     
  61.     /* run the program */
  62.     i = main();
  63.  
  64.     /* close up shop */
  65.     appl_exit(i);
  66. }
  67.  
  68. #define vdc(op,pi,ii,xx,yy) ct0=op;ct1=pi;ct2=ct4=0;ct3=ii;ct5=xx;ct6=yy;vdi()
  69.  
  70.  
  71. /* open virtual workstation */
  72.  
  73. v_opnvwk(in, h, out) 
  74. struct vdi_openin *in; 
  75. short *h; 
  76. struct vdi_openout *out; {
  77.     vdi0    = &ct0;
  78.     vdi1    = in;
  79.     vdi2    = &pi0;
  80.     vdi3    = out;
  81.     vdi4    = &(out->devicetyp);
  82.     vdc(100, 0, 11, 0, 1);
  83.     *h     = ct6;
  84.     vdi0    = &ct0;
  85.     vdi1    = &ii0;
  86.     vdi2    = &pi0;
  87.     vdi3    = &io0;
  88.     vdi4    = &po0;
  89. }
  90.  
  91. /* close virtual workstation */
  92.         
  93. v_clsvwk(h) short h; {
  94.     vdc(101, 0, 0, 0, h);
  95. }
  96.  
  97. v_clrwk(h) short h; {
  98.     vdc(3, 0, 0, 0, h);
  99. }
  100.  
  101. /* cursor control */
  102.  
  103. v_enter_cur(h) short h; {    /* enter cursor mode - shows cursor */
  104.     vdc(5, 0, 0, 3, h);
  105. }
  106.  
  107. v_exit_cur(h) short h; {    /* exit cursor mode - removes cursor */
  108.     vdc(5, 0, 0, 2, h);
  109. }
  110.  
  111. v_rvon(h) {             /* reverse video on - cursor text */
  112.     vdc(5, 0, 0, 13, h);
  113. }
  114.  
  115. v_rvoff(h) {            /* reverse video off - cursor text */
  116.     vdc(5, 0, 0, 14, h);
  117. }
  118.  
  119. v_curhome(h) {            /* home cursor */
  120.     vdc(5, 0, 0, 8, h);
  121. }
  122.  
  123. vs_curaddress(h, r, c) {     /* put cursor on row r (0-24) and col. c (0-79) */
  124.     ii0 = c;
  125.     ii1 = r;
  126.     vdc(5, 0, 2, 11, h);
  127. }
  128.  
  129. /* screen operations */
  130.  
  131. v_eeos(h) {            /* erase from cursor to end of screen */
  132.     vdc(5, 0, 0, 9, h);
  133. }
  134.  
  135. /* polymarkers */
  136.     
  137. v_pmarker(h, count, xy)    short xy[]; { /* plot markers at xy coords. passed */
  138.     vdi2 = xy;
  139.     vdc(7, count, 0, 0, h);
  140.     vdi2 = &pi0;
  141. }
  142.  
  143. vsm_color(h, color) {    /* sets the color that marker is plotted with */
  144.     return vdi_attr(h, 20, color); /* color: 0 - numcolors */
  145. }
  146.  
  147. vsm_height(h, height) {    /* set the height of plotted markers (not of type 1) */
  148.     pi0 = 0;
  149.     pi1 = height; /* height: in pels, 1 - maxy */
  150.     vdc(19, 1, 0, 0, h);
  151.     return po1;
  152. }
  153.  
  154. vsm_type(h, type) {    /* set marker type - returns type selected */
  155.     return vdi_attr(h, 18, type); /* type: 1 - nummarktyp */
  156. }
  157.  
  158. vqm_attributes(h, at) struct vdi_mattr *at; { /* query marker attributes */
  159.     vdi3 = at;
  160.     vdi4 = &(at->markwid);
  161.     vdc(36, 0, 0, 0, h);
  162.     vdi3 = &io0;
  163.     vdi4 = &po0;
  164. }
  165.  
  166. /* polylines */
  167.  
  168. v_pline(h, count, xy) short xy[]; { /* draw multi-segment line */
  169.     vdi2 = xy;
  170.     vdc(6, count, 0, 0, h);     /* count >= 2 */
  171.     vdi2 = &pi0;
  172. }
  173.  
  174. vsl_color(h, color) {    /* set line color - returns color selected */
  175.     return vdi_attr(h, 17, color);
  176. }
  177.  
  178. vsl_ends(h, begin, end)    { /* set line end styles */
  179.     ii0 = begin;
  180.     ii1 = end;
  181.     vdc(108, 0, 2, 0, h);
  182. }
  183.  
  184. vsl_type(h, type) {    /* set line type - returns type selected */
  185.     return vdi_attr(h, 15, type);
  186. }
  187.  
  188. vsl_udsty(h, pat) {    /* set user defined line type pattern */
  189.     vdi_attr(h, 113, pat); /* e.g. dash line type is: 0xFF00 */
  190. }
  191.  
  192. vsl_width(h, w) {    /* set line width - returns actual width */
  193.     pi0 = w;
  194.     vdc(16, 1, 0, 0, h);
  195.     return po0;
  196. }
  197.  
  198. vql_attributes(h, at) struct vdi_lattr *at; { /* query line attributes */
  199.     vdi3 = at;
  200.     vdi4 = &(at->linewid);
  201.     vdc(35, 0, 0, 0, h);
  202.     vdi3 = &io0;
  203.     vdi4 = &po0;
  204. }
  205.  
  206. /* text */
  207.  
  208. vst_alignment(h, hin, vin, hout, vout) 
  209. short *hout, *vout; {     /* set text alignment */
  210.     ii0 = hin;
  211.     ii1 = vin;
  212.     vdc(39, 0, 2, 0, h);
  213.     *hout = io0;
  214.     *vout = io1;
  215. }
  216.  
  217. vst_color(h, color) {    /* set text color - color selected returned */
  218.     return vdi_attr(h, 22, color);
  219. }
  220.  
  221. vst_effects(h, effects) { /* set text effects - effects selected returned */
  222.     return vdi_attr(h, 106, effects);
  223. }
  224.  
  225. vst_height(h, height) { /* set text height - absolute mode */
  226.     pi0 = 0;
  227.     pi1 = height; /* height: distance from baseline to top of char. cell */
  228.     vdc(12, 1, 0, 0, h);
  229. }
  230.  
  231. vst_point(h, height) { /* set text height - points mode, height returned */
  232.     /* distance between baselines of two consecutive lines */
  233.     return vdi_attr(h, 107, height);
  234. }
  235.  
  236. vst_rotation(h, angle) { /* set baseline vector - angle selected returned */
  237.     return vdi_attr(h, 13, angle); /* angle expressed in .1s of a degree */
  238. }
  239.  
  240. vst_font(h, font) {    /* set font - returns font selected */
  241.     return vdi_attr(h, 21, font);
  242. }
  243.  
  244. vswr_mode(h, mode) {    /* set writing mode - mode selected returned */
  245.     return vdi_attr(h, 32, mode);
  246. }
  247.  
  248. v_curtext(h, s) char *s; {
  249.     _vdi_tcpy(5, 0, 12, h, s);
  250. }
  251.  
  252. v_gtext(h, x, y, s) char *s; {
  253.     pi0 = x;
  254.     pi1 = y;
  255.     _vdi_tcpy(8, 2, 0, h, s);
  256. }
  257.  
  258. _vdi_tcpy(op, pin, p5, h, s) char *s; {
  259.     short    *ip, tbuf[140];
  260.     int    i;
  261.  
  262.     vdi1 = tbuf;
  263.     for (ip = tbuf, i = 0; (i < 140) && (*s != '\0'); ++i) {
  264.         *ip++ = *s++;
  265.     }
  266.     vdc(op, pin, i, p5, h);
  267.     vdi1 = &ii0;
  268. }
  269.  
  270. vqt_attributes(h, at) struct vdi_tattr *at; { /* query text attributes */
  271.     vdi3 = at;
  272.     vdi4 = &(at->charwid);
  273.     vdc(38, 0, 0, 0, h);
  274.     vdi3 = &io0;
  275.     vdi4 = &po0;
  276. }
  277.  
  278. /* graphic primitives */
  279.  
  280. v_arc(h, x, y, r, sa, ea) { /* draw arc - portion of a circle */
  281.     ii0 = sa;    /* start angle - .1s of degree */
  282.     ii1 = ea;    /* end angle */
  283.     pi0 = x;    /* center - x coord. */
  284.     pi1 = y;    /* center - y coord. */
  285.     pi6 = r;    /* radius */
  286.     vdc(11, 4, 2, 2, h);
  287. }
  288.  
  289. v_bar(h, xy) int *xy; {    /* draw a bar (box) */
  290.     pi0 = *xy;
  291.     pi1 = *++xy;
  292.     pi2 = *++xy;
  293.     pi3 = *++xy;
  294.     vdc(11, 2, 0, 1, h);
  295. }
  296.  
  297. v_circle(h, x, y, r) {    /* draw a circle */
  298.     pi0 = x;
  299.     pi1 = y;
  300.     pi4 = r;
  301.     vdc(11, 3, 0, 4, h);
  302. }
  303.  
  304. v_contourfill(h, x, y, color) {    /* fill area enclosing x,y */
  305.     pi0 = x;
  306.     pi1 = y;
  307.     ii0 = color; /* color < 0: boundry of any color other than xy's */
  308.     vdc(103, 1, 1, 0, h);
  309. }
  310.  
  311. v_ellarc(h, x, y, xr, yr, sa, ea) { /* draw an elliptical arc */
  312.     ii0 = sa;    /* start angle */
  313.     ii1 = ea; /* end angle */
  314.     pi0 = x;    /* center point x */
  315.     pi1 = y;    /* center point y */
  316.     pi2 = xr; /* x radius */
  317.     pi3 = yr; /* y radius */
  318.     vdc(11, 2, 2, 6, h);
  319. }
  320.  
  321. v_ellpie(h, x, y, xr, yr, sa, ea) { /* draw an elliptical pie slice */
  322.     ii0 = sa;
  323.     ii1 = ea;
  324.     pi0 = x;
  325.     pi1 = y;
  326.     pi2 = xr;
  327.     pi3 = yr;
  328.     vdc(11, 2, 2, 7, h);
  329. }
  330.  
  331. v_ellipse(h, x, y, xr, yr) {    /* draw an ellipse */
  332.     pi0 = x;
  333.     pi1 = y;
  334.     pi2 = xr;
  335.     pi3 = yr;
  336.     vdc(11, 2, 0, 5, h);
  337. }
  338.  
  339. v_rbox(h, xy) short *xy; { /* draw a rounded box */
  340.     pi0 = *xy; /* xy coordinates of lower left and upper right corners */
  341.     pi1 = *++xy;
  342.     pi2 = *++xy;
  343.     pi3 = *++xy;
  344.     vdc(11, 2, 0, 8, h);
  345. }
  346.  
  347. v_rfbox(h, xy) short *xy; { /* draw a rounded filled box */
  348.     pi0 = *xy; /* xy coordinates of lower left and upper right corners */
  349.     pi1 = *++xy;
  350.     pi2 = *++xy;
  351.     pi3 = *++xy;
  352.     vdc(11, 2, 0, 9, h);
  353. }
  354.  
  355. v_recfl(h, xy) short *xy; { /* draw a filled rectangle */
  356.     pi0 = *xy; /* xy coordinates of diagonally opposite corners */
  357.     pi1 = *++xy;
  358.     pi2 = *++xy;
  359.     pi3 = *++xy;
  360.     vdc(114, 2, 0, 0, h);
  361. }
  362.  
  363. /* area fill and attributes */
  364.  
  365. v_fillarea(h, count, xy) short xy[]; { 
  366.     vdi2 = xy; /* fill area defined by a multi-segment line */
  367.     vdc(9, count, 0, 0, h); /* count >= 2 */
  368.     vdi2 = &pi0;
  369. }
  370.  
  371. vsf_color(h, color) {    /* set fill color */
  372.     return vdi_attr(h, 25, color);
  373. }
  374.  
  375. vsf_perimeter(h, v_flag) { /* set fill perimeter visibility */
  376.     return vdi_attr(h, 104, v_flag); /* 0 = invisible, 1 = visible */
  377. }
  378.  
  379. vsf_interior(h, style) { /* set fill interior style */
  380.     return vdi_attr(h, 23, style);
  381. }
  382.  
  383. vsf_style(h, style) {    /* set fill style */
  384.     /* interior pattern: 0-23, interior hatch: 0-11 */
  385.     return vdi_attr(h, 24, style); 
  386. }
  387.  
  388. vqf_attributes (h, at)    struct vdi_fattr *at; {
  389.     /* inquire current fill area attributes */
  390.     vdi4 = at;
  391.     vdc(37, 0, 0, 0, h);
  392.     vdi4 = &po0;
  393. }
  394.  
  395. /* pixel operation */
  396.  
  397. v_get_pixel(h, x, y, pel, color) short *pel, *color; { /* get pixel value */
  398.     pi0 = x;
  399.     pi1 = y;
  400.     vdc(105, 1, 0, 0, h);
  401.     *pel = io0;
  402.     *color = io1;
  403. }
  404.  
  405. vro_cpyfm(h, mode, xy, src, des) short xy[]; struct mfdb *src, *des; {
  406.     struct    mfdb    **p;
  407.  
  408.     p = (struct mfdb **) &ct7;
  409.     *p = src;
  410.     *++p = des;
  411.     ii0 = mode;
  412.     vdi2 = xy;
  413.     vdc(109, 4, 1, 0, h);
  414.     vdi2 = &pi0;
  415. }
  416.  
  417. vq_color(h, index, set_flag, rgb) short rgb[]; {
  418.     /* inquire color representation */
  419.     ii0 = index;    /* color to enquire about */
  420.     ii1 = set_flag;    /* 0 = values set; 1 = values realized */
  421.     vdc(26, 0, 2, 0, h);
  422.     rgb[0] = io1;    /* red intensity - .1% */
  423.     rgb[1] = io2;    /* green intensity  */
  424.     rgb[2] = io3;    /* blue intensity */
  425. }
  426.  
  427. vs_color(h, index, rgb) short rgb[]; {    /* set color representation */
  428.     ii0 = index;
  429.     ii1 = rgb[0];    /* red */
  430.     ii2 = rgb[1];    /* green */
  431.     ii3 = rgb[2];    /* blue */
  432.     vdc(14, 0, 4, 0, h);
  433. }
  434.  
  435. /* mouse functions */
  436.  
  437. v_show_c(h, mstyle) {    /* show mouse */
  438.     ii0 = mstyle;
  439.     vdc(122, 0, 1, 0, h);
  440. }
  441.  
  442. v_hide_c(h) {    /* hide mouse */
  443.     vdc(123, 0, 0, 0, h);
  444. }
  445.  
  446. vsc_form(h, form) struct vdi_form *form; { /* define mouse shape */
  447.     vdi1 = form;
  448.     vdc(111, 0, 37, 0, h);
  449.     vdi1 = &ii0;
  450. }
  451.  
  452. vq_mouse(h, pstatus, px, py) short *pstatus, *px, *py; {
  453.     /* get mouse's status */
  454.     vdc(124, 0, 0, 0, h);
  455.     *pstatus = io0;
  456.     *px = po0;
  457.     *py = po1;
  458. }
  459.  
  460. vdi_attr(h, op, attr) { /* implements many common routines */
  461.     ii0 = attr;
  462.     vdc(op, 0, 1, 0, h);
  463.     return io0;
  464. }
  465.  
  466. /* GEM application init and exit */
  467.  
  468. appl_init() {
  469.     ct0 = 10;
  470.     ct2 = 1;
  471.     ct1 = ct3 = ct4 = 0;
  472.     aes();
  473.     return io0;
  474. }
  475.  
  476. appl_exit(i) { trap(1, TERM, i); }
  477.  
  478. /* VDI routines for the GEM library */
  479.  
  480. vq_extnd(handle, owflag, out) int *out; {
  481.     int i, j, *intout, *ptsout;
  482.     ct0 = 102;
  483.     ct1 = 0;
  484.     ct3 = 1;
  485.     ct6 = handle;
  486.     ii0 = owflag;
  487.     vdi();
  488.     intout = &io0;
  489.     for (i = 0; i < 45; i++) out[i] = intout[i];
  490.     ptsout = &po0;
  491.     for (j = 0; j < 12; j++) out[i++] = ptsout[j];
  492. }
  493.  
  494. /* 
  495.  * GEM:VDI set clipping rectangle 
  496.  *    flag = 0     no clipping
  497.  *    flag = 1    clipping on
  498.  *     pxy[] should contain the upper left and bottom right coords
  499.  */
  500.  
  501. vs_clip(handle, flag, pxy) int *pxy; {
  502.     ct0 = 129;
  503.     ct1 = 2;
  504.     ct3 = 1;
  505.     ct6 = handle;
  506.     ii0 = flag;
  507.     vdi2 = pxy;
  508.     vdi();
  509.     vdi2 = &pi0;
  510. }
  511.  
  512. /* GEM:VDI put justified text on the screen */
  513.  
  514. v_justified(handle, x, y, string, len, wspace, cspace) char *string; {
  515.     int *ip;
  516.     ct0 = 11;
  517.     ct1 = 2;
  518.     ct6 = handle;
  519.     ii0 = wspace;
  520.     ii1 = cspace;
  521.     ip = &ii2;
  522.     for (ct3 = 2; *ip++ = *string++; ct3++)
  523.         ;
  524.     pi0 = x;
  525.     pi1 = y;
  526.     pi2 = len;
  527.     vdi();
  528. }
  529.  
  530. /* AES: resource handling */
  531.  
  532. rsrc_gaddr(type, index, addr) long **addr; {
  533.     ct0 = 112;
  534.     ct1 = 2;
  535.     ct2 = ct4 = 1;
  536.     ct3 = 0;
  537.     ii0 = type;
  538.     ii1 = index;
  539.     aes();
  540.     *addr = ao0;
  541.     return io0;
  542. }
  543.  
  544. rsrc_saddr(type, index, addr) long *addr; {
  545.     ct0 = 113;
  546.     ct1 = 2;
  547.     ct2 = ct3 = 1;
  548.     ct4 = 0;
  549.     ii0 = type;
  550.     ii1 = index;
  551.     ai0 = addr;
  552.     aes();
  553.     return io0;
  554. }
  555.  
  556. /* graphics handling */
  557.  
  558. graf_handle(wchar, hchar, wbox, hbox) int *wchar, *hchar, *wbox, *hbox; {
  559.     ct0 = 77;
  560.     ct2 = 5;
  561.     ct1 = ct3 = ct4 = 0;
  562.     aes();
  563.     *wchar = io1;
  564.     *hchar = io2;
  565.     *wbox = io3;
  566.     *hbox = io4;
  567.     return io0;
  568. }
  569.  
  570. graf_rubberbox(x, y, minw, minh, lastw, lasth) int *lastw, *lasth; { 
  571.     ct0 = 70;
  572.     ct1 = 4;
  573.     ct2 = 3;
  574.     ct3 = ct4 = 0;
  575.     ii0 = x;
  576.     ii1 = y;
  577.     ii2 = minw;
  578.     ii3 = minh;
  579.     aes();
  580.     *lastw = io1;
  581.     *lasth = io2;
  582.     return io0;
  583. }
  584.  
  585. graf_dragbox(dw, dh, sx, sy, bx, by, bw, bh, endx, endy) int *endx, *endy; {
  586.     ct0 = 71;
  587.     ct1 = 8;
  588.     ct2 = 3;
  589.     ct3 = ct4 = 0;
  590.     ii0 = dw;
  591.     ii1 = dh;
  592.     ii2 = sx;
  593.     ii3 = sy;
  594.     ii4 = bx;
  595.     ii5 = by;
  596.     ii6 = bw;
  597.     ii7 = bh;
  598.     aes();
  599.     *endx = io1;
  600.     *endy = io2;
  601.     return io0;
  602. }
  603.  
  604. graf_movebox(w, h, sx, sy, dx, dy) {
  605.     ct0 = 72;
  606.     ct1 = 6;
  607.     ct2 = 1;
  608.     ct3 = ct4 = 0;
  609.     ii0 = w;
  610.     ii1 = h;
  611.     ii2 = sx;
  612.     ii3 = sy;
  613.     ii4 = dx;
  614.     ii5 = dy;
  615.     aes();
  616.     return io0;
  617. }
  618.  
  619. graf_growbox(bx, by, bw, bh, ex, ey, ew, eh) {
  620.     ct0 = 73;
  621.     ct1 = 8;
  622.     ct2 = 1;
  623.     ct3 = ct4 = 0;
  624.     aes2 = &bx;
  625.     aes();
  626.     aes2 = &ii0;
  627.     return io0;
  628. }
  629.     
  630. graf_shrinkbox(ex, ey, ew, eh, bx, by, bw, bh) {
  631.     ct0 = 73;
  632.     ct1 = 8;
  633.     ct2 = 1;
  634.     ct3 = ct4 = 0;
  635.     aes2 = &ex;
  636.     aes();
  637.     aes2 = &ii0;
  638.     return io0;
  639. }
  640.  
  641. graf_watchbox(tree, obj, instate, outstate) int *tree; { 
  642.     ct0 = 75;
  643.     ct1 = 4;
  644.     ct2 = ct3 = 1;
  645.     ct4 = 0;
  646.     ii1 = obj;
  647.     ii2 = instate;
  648.     ii3 = outstate;
  649.     ai0 = tree;
  650.     aes();
  651.     return io0;
  652. }
  653.  
  654. graf_slidebox(tree, parent, obj, vh) int *tree; { 
  655.     ct0 = 76;
  656.     ct1 = 3;
  657.     ct2 = ct3 = 1;
  658.     ct4 = 0;
  659.     ii0 = parent;
  660.     ii1 = obj;
  661.     ii2 = vh;
  662.     ai0 = tree;
  663.     aes();
  664.     return io0;
  665. }
  666.  
  667. graf_mouse(type, shape) int *shape; { 
  668.     ct0 = 78;
  669.     ct1 = ct2 = ct3 = 1;
  670.     ct4 = 0;
  671.     ii0 = type;
  672.     ai0 = shape;
  673.     aes();
  674.     return io0;
  675. }
  676.  
  677. graf_mkstate(x, y, mstate, kstate) int *x, *y, *mstate, *kstate; { 
  678.     ct0 = 79;
  679.     ct1 = ct3 = ct4 = 0;
  680.     ct2 = 5;
  681.     aes();
  682.     *x = io1;
  683.     *y = io2;
  684.     *mstate = io3;
  685.     *kstate = io4;
  686.     return io0;
  687. }
  688.  
  689. /* window handling */
  690.  
  691. wind_get(handle, gfld, gw1, gw2, gw3, gw4) int *gw1, *gw2, *gw3, *gw4; {
  692.     ct0 = 104;
  693.     ct1 = 2;
  694.     ct2 = 5;
  695.     ct3 = ct4 = 0;
  696.     ii0 = handle;
  697.     ii1 = gfld;
  698.     aes();
  699.     *gw1 = io1;
  700.     *gw2 = io2;
  701.     *gw3 = io3;
  702.     *gw4 = io4;
  703.     return io0;
  704. }
  705.  
  706. wind_create(kind, x, y, w, h) {
  707.     ct0 = 100;
  708.     ct1 = 5;
  709.     ct2 = 1;
  710.     ct3 = ct4 = 0;
  711.     ii0 = kind;
  712.     ii1 = x;
  713.     ii2 = y;
  714.     ii3 = w;
  715.     ii4 = h;
  716.     aes();
  717.     return io0;
  718. }
  719.  
  720. wind_set(handle, field, s1, s2, s3, s4) {
  721.     ct0 = 105;
  722.     ct1 = 6;
  723.     ct2 = 1;
  724.     ct3 = ct4 = 0;
  725.     ii0 = handle;
  726.     ii1 = field;
  727.     ii2 = s1;
  728.     ii3 = s2;
  729.     ii4 = s3;
  730.     ii5 = s4;
  731.     aes();
  732.     return io0;
  733. }
  734.  
  735. wind_open(handle, x, y, w, h) {
  736.     ct0 = 101;
  737.     ct1 = ct2 = 5;
  738.     ct3 = ct4 = 0;
  739.     ii0 = handle;
  740.     ii1 = x;
  741.     ii2 = y;
  742.     ii3 = w;
  743.     ii4 = h;
  744.     aes();
  745.     return io0;
  746. }
  747.  
  748. wind_close(handle) { 
  749.     ct0 = 102;
  750.     ct1 = ct2 = 1;
  751.     ct3 = ct4 = 0;
  752.     ii0 = handle;
  753.     aes();
  754.     return io0;
  755. }
  756.  
  757. wind_delete(handle) {
  758.     ct0 = 103;
  759.     ct1 = ct2 = 1;
  760.     ct3 = ct4 = 0;
  761.     ii0 = handle;
  762.     aes();
  763.     return io0;
  764. }
  765.  
  766. wind_find(x, y) {
  767.     ct0 = 106;
  768.     ct1 = 2;
  769.     ct2 = 1;
  770.     ct3 = ct4 = 0;
  771.     ii0 = x;
  772.     ii1 = y;
  773.     aes();
  774.     return io0;
  775. }
  776.  
  777. wind_update(n) {
  778.     ct0 = 107;
  779.     ct1 = ct2 = 1;
  780.     ct3 = ct4 = 0;
  781.     ii0 = n;
  782.     aes();
  783.     return io0;
  784. }
  785.  
  786. wind_calc(
  787.     type, kind, xi, yi, wi, hi, 
  788.     xo, yo, wo, ho) int *xo, *yo, *wo, *ho; {
  789.     ct0 = 108;
  790.     ct1 = 6;
  791.     ct2 = 5;
  792.     ct3 = ct4 = 0;
  793.     ii0 = type;
  794.     ii1 = kind;
  795.     ii2 = xi;
  796.     ii3 = yi;
  797.     ii4 = wi;
  798.     ii5 = hi;
  799.     aes();
  800.     *xo = io1;
  801.     *yo = io2;
  802.     *wo = io3;
  803.     *ho = io4;
  804.     return io0;
  805. }
  806.  
  807. /* event handling */
  808.  
  809. event_multi(
  810.   flags, clicks, mask, state, 
  811.   af, ax, ay, aw, ah,
  812.   bf, bx, by, bw, bh,
  813.   buff, lo, hi,
  814.   ox, oy, obut, ostate, okret, obret) 
  815.     int *ox, *oy, *obut, *ostate, *okret, *obret;
  816. {
  817.     ct0 = 25;
  818.     ct1 = 16;
  819.     ct2 = 7;
  820.     ct3 = 1;
  821.     ct4 = 0;
  822.     ii0 = flags;
  823.     ii1 = clicks;
  824.     ii2 = mask;
  825.     ii3 = state;
  826.     ii4 = af;
  827.     ii5 = ax;
  828.     ii6 = ay;
  829.     ii7 = aw;
  830.     ii8 = ah;
  831.     ii9 = bf;
  832.     ii10 = bx;
  833.     ii11 = by;
  834.     ii12 = bw;
  835.     ii13 = bh;
  836.     ii14 = lo;
  837.     ii15 = hi;
  838.     ai0 = buff;
  839.     aes();
  840.     *ox = io1;
  841.     *oy = io2;
  842.     *obut = io3;
  843.     *ostate = io4;
  844.     *okret = io5;
  845.     *obret = io6;
  846.     return io0;
  847. }
  848.  
  849. /* object handling */
  850.  
  851. objc_draw(tree, start, depth, xclip, yclip, wclip, hclip) int *tree; { 
  852.     ct0 = 42;
  853.     ct1 = 6;
  854.     ct2 = ct3 = 1;
  855.     ct4 = 0;
  856.     ii0 = start;
  857.     ii1 = depth;
  858.     ii2 = xclip;
  859.     ii3 = yclip;
  860.     ii4 = wclip;
  861.     ii5 = hclip;
  862.     ai0 = tree;
  863.     aes();
  864.     return io0;
  865. }
  866.  
  867. objc_find(tree, start, depth, x, y) int *tree; { 
  868.     ct0 = 43;
  869.     ct1 = 4;
  870.     ct2 = ct3 = 1;
  871.     ct4 = 0;
  872.     ii0 = start;
  873.     ii1 = depth;
  874.     ii2 = x;
  875.     ii3 = y;
  876.     ai0 = tree;
  877.     aes();
  878.     return io0;
  879. }
  880.  
  881. objc_offset(tree, object, xoff, yoff) int *tree, *xoff, *yoff; {
  882.     ct0 = 43;
  883.     ct1 = 1;
  884.     ct2 = 3;
  885.     ct3 = 1;
  886.     ct4 = 0;
  887.     ii0 = object;
  888.     ai0 = tree;
  889.     aes();
  890.     *xoff = io1;
  891.     *yoff = io2;
  892.     return io0;
  893. }
  894.  
  895. objc_edit(tree, object, ch, idx, kind, newidx) int *tree, *newidx; {
  896.     ct0 = 46;
  897.     ct1 = 4;
  898.     ct2 = 2;
  899.     ct3 = 1;
  900.     ct4 = 0;
  901.     ii0 = object;
  902.     ii1 = ch;
  903.     ii2 = idx;
  904.     ii3 = kind;
  905.     ai0 = tree;
  906.     aes();
  907.     *newidx = io1;
  908.     return io0;
  909. }
  910.  
  911. objc_change(tree, object, resvd, x, y, w, h, state, redraw) int *tree; {
  912.     ct0 = 47;
  913.     ct1 = 8;
  914.     ct2 = ct3 = 1;
  915.     ct4 = 0;
  916.     ii0 = object;
  917.     ii1 = resvd;
  918.     ii2 = x;
  919.     ii3 = y;
  920.     ii4 = w;
  921.     ii5 = h;
  922.     ii6 = state;
  923.     ii7 = redraw;
  924.     ai0 = tree;
  925.     aes();
  926.     return io0;
  927. }
  928.  
  929. /* menu handling */
  930.  
  931. menu_bar(tree, show) int *tree; { 
  932.     ct0 = 30;
  933.     ct1 = ct2 = ct3 = 1;
  934.     ct4 = 0;
  935.     ii0 = show;
  936.     ai0= tree;
  937.     aes();
  938.     return io0;
  939. }
  940.  
  941. menu_icheck(tree, item, check) int *tree; {
  942.     ct0 = 31;
  943.     ct1 = 2;
  944.     ct2 = ct3 = 1;
  945.     ct4 = 0;
  946.     ii0 = item;
  947.     ii1 = check;
  948.     ai0 = tree;
  949.     aes();
  950.     return io0;
  951. }
  952.  
  953. menu_enable(tree, item, enable) int *tree; {
  954.     ct0 = 32;
  955.     ct1 = 2;
  956.     ct2 = ct3 = 1;
  957.     ct4 = 0;
  958.     ii0 = item;
  959.     ii1 = enable;
  960.     ai0 = tree;
  961.     aes();
  962.     return io0;
  963. }
  964.  
  965. menu_tnormal(tree, title, normal) int *tree; {
  966.     ct0 = 33;
  967.     ct1 = 2;
  968.     ct2 = ct3 = 1;
  969.     ct4 = 0;
  970.     ii0 = title;
  971.     ii1 = normal;
  972.     ai0 = tree;
  973.     aes();
  974.     return io0;
  975. }
  976.  
  977. menu_text(tree, item, text) int *tree; char *text; {
  978.     ct0 = 34;
  979.     ct1 = ct2 = 1;
  980.      ct3 = 2;
  981.     ct4 = 0;
  982.     ii0 = item;
  983.     ai0 = tree;
  984.     ai1 = text;
  985.     aes();
  986.     return io0;
  987. }
  988.  
  989. menu_register(id, string) char *string; {
  990.     ct0 = 35;
  991.     ct1 = ct2 = ct3 = 1;
  992.     ct4 = 0;
  993.     ii0 = id;
  994.     ai0 = string;
  995.     aes();
  996.     return io0;
  997. }
  998.  
  999. /* form handling */
  1000.  
  1001. form_pf(fmt, args) char *fmt; int args; {
  1002.     extern char _pfb[1];
  1003.     _dopf(_pfb, fmt, &args);
  1004.     form_alert(0, _pfb);
  1005. }
  1006.  
  1007. form_do(tree, start) int *tree; {
  1008.     ct0 = 50;
  1009.     ct1 = ct3 = 1;
  1010.     ct2 = 2;
  1011.     ct4 = 0;
  1012.     ii0 = start;
  1013.     ai0 = tree;
  1014.     aes();
  1015.     return io0;
  1016. }
  1017.  
  1018. form_dial(flag, sx, sy, sw, sh, bx, by, bw, bh) {
  1019.     ct0 = 51;
  1020.     ct1 = 9;
  1021.     ct3 = ct2 = 1;
  1022.     ct4 = 0;
  1023.     ii0 = flag;
  1024.     ii1 = sx;
  1025.     ii2 = sy;
  1026.     ii3 = sw;
  1027.     ii4 = sh;
  1028.     ii5 = bx;
  1029.     ii6 = by;
  1030.     ii7 = bw;
  1031.     ii8 = bh;
  1032.     aes();
  1033.     return io0;
  1034. }
  1035.  
  1036. form_center(tree, x, y, w, h) int *tree, *x, *y, *w, *h; {
  1037.     ct0 = 54;
  1038.     ct1 = 0;
  1039.     ct3 = 5;
  1040.     ct2 = 1;
  1041.     ct4 = 0;
  1042.     ai0 = tree;
  1043.     aes();
  1044.     *x = io1;
  1045.     *y = io2;
  1046.     *w = io3;
  1047.     *h = io4;
  1048.     return io0;
  1049. }
  1050.  
  1051. form_error(num) {
  1052.     ct0 = 53;
  1053.     ct1 = ct2 = 1;
  1054.     ct3 = ct4 = 0;
  1055.     ii0 = num;
  1056.     aes();
  1057.     return io0;
  1058. }
  1059.  
  1060. form_alert(button, string) char *string; {
  1061.     ct0 = 52;
  1062.     ct1 = ct2 = ct3 = 1;
  1063.     ct4 = 0;
  1064.     ii0 = button;
  1065.     ai0 = string;
  1066.     aes();
  1067.     return io0;
  1068. }
  1069.  
  1070.  
  1071. /* AES and VDI support routines */
  1072.  
  1073. aes() {
  1074.     /* 
  1075.          * load address of aes parameter block into a0
  1076.          * transfer a0 to d1
  1077.          * load 200 into d0
  1078.          * trap #2
  1079.          */
  1080.     asm( lag aes0 0   tad 0 1   ldw 200 0   trp 2 );
  1081. }
  1082.  
  1083. vdi() {
  1084.     /* 
  1085.          * load address of vdi parameter block into a0
  1086.          * transfer a0 to d1
  1087.          * load 115 into d0
  1088.          * trap #2
  1089.          */
  1090.     asm( lag vdi0 0   tad 0 1   ldw 115 0   trp 2 );
  1091. }
  1092.